<br>

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="utf-8">
	<title><?php echo $title; ?></title>
</head>

<body>

<script>
<?php
$D=0;
foreach($jawaban as $data){
	$D++;
}
echo "var jumlah = ".$D.";\n";
?>
function check(){
	jum = 0;
	jum_2 = 0;
    for(i=0;i<=jumlah;i++){
        id 	 = "check_jawaban"+i;
		id_2 = "check_kunci"+i;
		
        td1 = "k1"+i;
        td2 = "k2"+i;
        td3 = "k3"+i;
        td4 = "k4"+i;
		td5 = "k5"+i;
		
        if(document.getElementById(id).checked){
            document.getElementById(td1).style.backgroundColor = "lightblue";
            document.getElementById(td2).style.backgroundColor = "lightblue";
            document.getElementById(td3).style.backgroundColor = "lightblue";
            document.getElementById(td4).style.backgroundColor = "lightblue";
            document.getElementById(td5).style.backgroundColor = "white";
			jum = jum + 1;
			document.getElementById(id_2).checked = false;	
			
			//document.getElementById("skor"+i).value = '';
        }else if(document.getElementById(id_2).checked){
			document.getElementById(td1).style.backgroundColor = "lightgreen";
            document.getElementById(td2).style.backgroundColor = "lightgreen";
            document.getElementById(td3).style.backgroundColor = "lightgreen";
            document.getElementById(td4).style.backgroundColor = "white";
            document.getElementById(td5).style.backgroundColor = "lightgreen";
		}else {
            document.getElementById(td1).style.backgroundColor = "white";
            document.getElementById(td2).style.backgroundColor = "white";
            document.getElementById(td3).style.backgroundColor = "white";
            document.getElementById(td4).style.backgroundColor = "white";
            document.getElementById(td5).style.backgroundColor = "white";
        }
    }
}


function check_2(){
	jum_2 = 0;
    for(i=0;i<=jumlah;i++){
        id 	 = "check_jawaban"+i;
		id_2 = "check_kunci"+i;
		
        td1 = "k1"+i;
        td2 = "k2"+i;
        td3 = "k3"+i;
        td4 = "k4"+i;
		td5 = "k5"+i;
		
		if(document.getElementById(id_2).checked){
			document.getElementById(td1).style.backgroundColor = "lightgreen";
            document.getElementById(td2).style.backgroundColor = "lightgreen";
            document.getElementById(td3).style.backgroundColor = "lightgreen";
            document.getElementById(td4).style.backgroundColor = "white";
            document.getElementById(td5).style.backgroundColor = "lightgreen";
			jum_2 = jum_2 + 1;
			document.getElementById(id).checked = false;
		}else if(document.getElementById(id).checked){
            document.getElementById(td1).style.backgroundColor = "lightblue";
            document.getElementById(td2).style.backgroundColor = "lightblue";
            document.getElementById(td3).style.backgroundColor = "lightblue";
            document.getElementById(td4).style.backgroundColor = "lightblue";
            document.getElementById(td5).style.backgroundColor = "white";
		}else {
            document.getElementById(td1).style.backgroundColor = "white";
            document.getElementById(td2).style.backgroundColor = "white";
            document.getElementById(td3).style.backgroundColor = "white";
            document.getElementById(td4).style.backgroundColor = "white";
            document.getElementById(td5).style.backgroundColor = "white";
        }
    }
	document.getElementById("nilai"+i).innerHTML = '';
}
</script>

<?php
function sinonim($sinonim){
	if($sinonim!=''){
		?>
		<script>
			document.getElementById('sinonim').checked = true;
		</script>
		<?php
	}else{
		?>
		<script>
			document.getElementById('sinonim').checked = false;
		</script>
		<?php
	}
}

function check_list($hasil_proses, $nilai){
	foreach($hasil_proses['no'] as $value){
		?>
		<script>
		var i = <?php echo $value ?>;
		var n = <?php echo round($nilai['nilai'][$value],$hasil_proses['error_digit']) ?>;
		id  = "check_jawaban"+i;
		td1 = "k1"+i;
		td2 = "k2"+i;
		td3 = "k3"+i;
		td4 = "k4"+i;
		td5 = "k5"+i;
		
		document.getElementById(td1).style.backgroundColor = "lightblue";
		document.getElementById(td2).style.backgroundColor = "lightblue";
		document.getElementById(td3).style.backgroundColor = "lightblue";
		document.getElementById(td4).style.backgroundColor = "lightblue";
		document.getElementById(td5).style.backgroundColor = "white";
		document.getElementById(id).checked = true;
		
		document.getElementById("nilai"+i).innerHTML = n;
		</script>
		<?php
	}
		
	foreach($hasil_proses['no_kunci'] as $value){
		?>
		<script>
		var i = <?php echo $value ?>;
		id_2  = "check_kunci"+i;
		
		td1 = "k1"+i;
		td2 = "k2"+i;
		td3 = "k3"+i;
		td4 = "k4"+i;
		td5 = "k5"+i;
		
		document.getElementById(td1).style.backgroundColor = "lightgreen";
		document.getElementById(td2).style.backgroundColor = "lightgreen";
		document.getElementById(td3).style.backgroundColor = "lightgreen";
		document.getElementById(td4).style.backgroundColor = "white";
		document.getElementById(td5).style.backgroundColor = "lightgreen";
		document.getElementById(id_2).checked = true;
		</script>
		<?php
	}
}
?>
<div id="container">
	<h1>Selamat datang di perhitungan manual Algoritma <?php echo $title; ?>!</h1>

	<div id="body">
		<?php echo form_open(base_url().'main/'.$title); ?>
		<table class="table table-bordered table-hover table-striped tablesorter">
		<tr>
			<td>No</td>
			<td>Jawaban</td>
			<td>Nilai</td>
			<td>Jawaban</td>
			<td>Kunci</td>
			<td>Skor</td>
		</tr>
		<?php
		$no=0;
		foreach($jawaban as $data){
		?>
		<tr>
			<tr>
			<td id="k1<?php echo$no; ?>"><?php echo$no+1; ?></td>
			<td id="k2<?php echo$no; ?>"><?php echo$data['kalimat']; ?></td>
			<td id="k3<?php echo$no; ?>"><span id="nilai<?php echo$no; ?>"></span></td>
			<td id="k4<?php echo$no; ?>">
			<input type="checkbox" onclick="check()" value="<?php echo$no; ?>" id="check_jawaban<?php echo$no; ?>" name="check_jawaban[<?php echo$no; ?>]">
			<input type="hidden" name="data_jawaban<?php echo$no; ?>" value="<?php echo$data['kalimat']; ?>">
			</td>
			<td id="k5<?php echo$no; ?>">
			<input type="checkbox" onclick="check_2()" value="<?php echo$no; ?>" id="check_kunci<?php echo$no; ?>" name="check_kunci[<?php echo$no; ?>]">
			<input type="hidden" name="data_kunci<?php echo$no; ?>" value="<?php echo$data['kalimat']; ?>">
			</td>
			<td><input type="text" name="skor<?php echo$no; ?>" style="width:50;" value="<?php echo$data['skor']; ?>" id="skor<?php echo$no; ?>"></td>
			</tr>
		</tr>
		<?php
		$no++;
		}
		?>
		<table>
		<br>
		<div class="col-lg-1">
		<?php
			$data_submit = array('name' => 'proses_submit', 'class' => 'btn btn-primary', 'value' => 'Proses', 'style' => 'width:83px');
			echo form_submit($data_submit);
		?>
		</div>
		<div class="col-lg-2" style="width:105px">
			<div class="form-control" style="width:100px" data-toggle="tooltip" data-placement="bottom" title="Sinonim">
				<label class="checkbox-inline"><input name="sinonim" id="sinonim" type="checkbox" value="sinonim" onclick="this.form.submit()"> sinonim</label>
			</div>
		</div>
		<?php
		if($title == "tfidf"){
			if($hasil_tfidf_token){
				$jumlah_ngram = $hasil_tfidf_token['ngram'];
				?>  
				<div class="form-actions">
					<div class="col-lg-2" style="width:105px">
						<select class="form-control" name="ngram" id="ngram" onchange="this.form.submit()" style="width:100px">
							<option value="<?php echo$ngram; ?>"><?php echo$ngram; ?> kata</option>
							<?php
							for($i=1; $i<=$jumlah_ngram; $i++){
								if($i!=$ngram){
								?><option value="<?php echo$i; ?>"><?php echo$i; ?></option><?php
								}
							}
							?>
						</select> 				
					</div>
					
					<div class="col-lg-2" style="width:105px">
						<select class="form-control" name="error_digit" id="error_digit" onchange="this.form.submit()" style="width:100px">
							<option value="<?php echo$error_digit; ?>"><?php echo$error_digit; ?> digit</option>
							<?php
							for($j=1; $j<=10; $j++){
								if($j!=$error_digit){
								?><option value="<?php echo$j; ?>"><?php echo$j; ?></option><?php
								}
							}
							?>
						</select>
					</div>
				</div>
				<?php /**?><span><input type="checkbox" onclick="" value="show_tabel" id="show_tabel" name="show_tabel"> Show Table</span>
				<span><input type="checkbox" onclick="" value="sinonim" id="sinonim" name="sinonim"> Sinonim</span>
				<?php/**/ ?>
				<br>
				<br>
				<br>
				
				<?php
				foreach($hasil_tfidf_token['jawaban']['no'] as $no_jawaban){
				echo"Jawaban : ".$hasil_tfidf_token['jawaban']['asli'][$no_jawaban]."<br>";
				/**/
				?>
				
				<table border="1" width="100%" style="border-collapse:collapse" bordercolor="#999999">
					<tr>
						<td>Token</td>
						<td>Jawaban</td>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td>Kunci <?php echo$no_kunci; ?></td>
							<?php } ?>
						<td>df</td>
						<td>D/df</td>
						<td>IDF log(D/df)</td>
						<td>W Jawaban</td>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td>W Kunci <?php echo$no_kunci; ?></td>
							<?php } ?>
					</tr>
					<?php
					foreach($hasil_proses['jawaban'][$no_jawaban]['S1'] as $no_token){
					?>
					<tr>
						<td><?php echo$no_token; ?></td>
						<td><?php echo"(".$hasil_proses['jawaban'][$no_jawaban]['hasil'][$no_token].") "//.$hasil_proses['jawaban'][$no_jawaban]['S2'][$no_token]; ?></td>
							
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php echo"(".$hasil_proses['kunci'][$no_jawaban][$no_kunci]['hasil'][$no_token].") "//.$hasil_proses['kunci'][$no_jawaban][$no_kunci]['S2'][$no_token]; ?></td>
							<?php } ?>
							
						<td><?php echo$hasil_proses['df'][$no_jawaban][$no_token]; ?></td>
						<td><?php echo$hasil_proses['D/df']['D/df'][$no_jawaban][$no_token]; ?></td>
						<td><?php echo$hasil_proses['D/df']['log'][$no_jawaban][$no_token]; ?></td>
						<td><?php echo$hasil_proses['W']['jawaban'][$no_jawaban][$no_token]; ?></td>
							
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php 
							if($hasil_proses['jawaban'][$no_jawaban]['hasil'][$no_token]>0) {echo"<font color='lightblue'>".$hasil_proses['W']['kunci'][$no_jawaban][$no_kunci][$no_token]."</font>";}
							else{echo$hasil_proses['W']['kunci'][$no_jawaban][$no_kunci][$no_token];}
							?></td>
							<?php } ?>
					</tr>
					<?php
					}
					?>
				</table>
				<br>
				
				<?php
				foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){
					echo"bobot (W) untuk kunci [".$no_kunci."] = ";
					echo$hasil_proses['bobot_W'][$no_jawaban][$no_kunci];
					echo"<br>";
				}
				echo"<br>";
				?>
				
				Vector Space Model
				<table border="1" width="" style="border-collapse:collapse" bordercolor="#999999">
					<tr>
						<td>Token</td>
						<td>Jawaban</td>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td>Kunci <?php echo$no_kunci; ?></td>
							<?php } ?>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td>Jawaban * Kunci <?php echo$no_kunci; ?></td>
							<?php } ?>
					</tr>
					<?php
					foreach($hasil_proses['jawaban'][$no_jawaban]['S1'] as $no_token){
					?>
					<tr>
						<td><?php echo$no_token; ?></td>
						<td><?php echo$hasil_proses['VSM']['jawaban'][$no_jawaban][$no_token]; ?></td>
							
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php 
							if($hasil_proses['jawaban'][$no_jawaban]['hasil'][$no_token]>0) {echo"<font color='lightblue'>".$hasil_proses['VSM']['kunci'][$no_jawaban][$no_kunci][$no_token]."</font>";}
							else{echo$hasil_proses['VSM']['kunci'][$no_jawaban][$no_kunci][$no_token];}
							?></td>
							<?php } ?>
							
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php 
							if($hasil_proses['jawaban'][$no_jawaban]['hasil'][$no_token]>0) {echo"<font color='lightblue'>".$hasil_proses['kkdoc'][$no_jawaban][$no_kunci][$no_token]."</font>";}
							else{echo$hasil_proses['kkdoc'][$no_jawaban][$no_kunci][$no_token];}
							?></td>
							<?php } ?>
					</tr>
					<?php
					}
					?>
					<tr>
						<td></td>
						<?php
						$jumlah = count($hasil_tfidf_token['kunci']['no']);
						?>
						<td colspan="<?php echo$jumlah+1; ?>">sqrt</td>
						<td colspan="<?php echo$jumlah; ?>">sum</td>
					</tr>
					<tr>
						<td></td>
						<td><?php echo$hasil_proses['sqrt']['jawaban_2'][$no_jawaban]; ?></td>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php echo$hasil_proses['sqrt']['kuadrat'][$no_jawaban][$no_kunci]; ?></td>
							<?php } ?>
							<?php foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){ ?>
						<td><?php echo$hasil_proses['sqrt']['kkdoc'][$no_jawaban][$no_kunci]; ?></td>
							<?php } ?>
					</tr>
				</table>
				<br>
				
				<?php
				/**/
				echo"cosin untuk jawaban [".$no_jawaban."] = ".$hasil_proses['cosin']['jawaban'][$no_jawaban]."<br>";
				foreach($hasil_tfidf_token['kunci']['no'] as $no_kunci){
					echo"cosin untuk kunci [".$no_kunci."] = ";
					echo$hasil_proses['cosin'][$no_jawaban][$no_kunci];
					echo"<br>";
				}
				?>
				
				<br><br>
				
				<?php
				}
				?>
				
				<?php
				//print_r($hasil_tfidf_token);
				//print_r($hasil_proses);
				check_list($hasil_proses, $nilai);
			}
		}
		else{
			if($kalimat){
			?> 			
			<div class="form-actions">
				<div class="col-lg-2" style="width:105px">
				<select class="form-control" name="error_digit" id="error_digit" onchange="this.form.submit()" style="width:100px">
					<option value="<?php echo$error_digit; ?>"><?php echo$error_digit; ?> digit</option>
					<?php
					for($j=1; $j<=10; $j++){
						if($j!=$error_digit){
						?><option value="<?php echo$j; ?>"><?php echo$j; ?></option><?php
						}
					}
					?>
				</select>
				</div>
			</div>
			<br>
			<br>
			<table class="table table-bordered table-hover table-striped tablesorter">
				<tr>
					<td width="20%">Kunci</td>
					<td width="65%">Jawaban</td>
					<td width="15%">Bleu</td>
				</tr>
				<?php
				foreach($kalimat['check_kunci'] as $kunci){
				?>
				<tr>
					<td><?php echo"[".$kunci."] --> ".$kalimat['kunci'][$kunci]; ?></td>
					<td colspan="2">
					<?php
					foreach($kalimat['check_jawaban'] as $jawaban){
						?>
						<table>
						<tr>
							<td><?php echo"[".$jawaban."] --> ".$kalimat['jawaban_siswa'][$jawaban]; ?></td>
							<td width="18.75%"><?php echo"[".$hasil_proses['BLEU'][$kunci][$jawaban]."] ".$nilai['normal'][$jawaban][$kunci]; ?></td>
						</tr>
						</table>
						<?php
					}
					?>
					</td>
				</tr>
				<?php
				}
				?>
			<table>
			
			<?php
				check_list($hasil_proses, $nilai);
			}
		}
	
	sinonim($sinonim);
	
	echo form_close();
	?>
	</div>
	<br>
	<p class="footer"><a href='<?php echo base_url()."main"; ?>'>Home</a> Page rendered in <strong>{elapsed_time}</strong> seconds</p>
</div>

</body>
</html>